/**
 * // Definition for a Node.
 * function Node(val,children) {
 *    this.val = val;
 *    this.children = children;
 * };
 */

/**
 * @param {Node|null} root
 * @return {number[][]}
 */
var levelOrder = function(root) {
    const queue=[root],res=[]
    if(!root)return res
    while(queue.length){
      let len=queue.length,temp=[]
      for(let i=1;i<=len;i++){
       let node=queue.shift()
       temp.push(node.val)
       if(node.children){
            for(const v of node.children){
           queue.push(v)
       }
       }
      
      } 
      res.push(temp)
    }   
    return res
   };